#coding=utf-8

#Main Thread
#Last Modified 2007-05-20
import app,threading,time,indexer,os,vglobals



workingThreads = []


class appWorker(threading.Thread):
    workingThreads = []
    def run (self):
        app.main()
    	
	
class uiWorker(threading.Thread):
	def run (self):
            taskbar.main()
		

# taskbar ico
import taskbar
vglobals.UI_THREAD = uiWorker()
workingThreads.append(vglobals.UI_THREAD)

# desktop crawl
vglobals.CRAWL_THREAD = indexer.crawl_thread()
workingThreads.append(vglobals.CRAWL_THREAD)

# filesystem watcher
vglobals.WATCHER_THREAD =  indexer.watcher_thread()
workingThreads.append(vglobals.WATCHER_THREAD)

# indexer
vglobals.INDEXER_THREAD = indexer.indexer_thread()
workingThreads.append(vglobals.INDEXER_THREAD)


# web server
vglobals.WEBSERVER_THREAD = appWorker()
workingThreads.append(vglobals.WEBSERVER_THREAD)

print workingThreads
for t in workingThreads:
        # set as deamon thread
        t.setDaemon(True)
	t.start()
        

# Quit main thread if STOP_FLAG had been turned into True
while(not vglobals.STOP_FLAG):
      # jobs: dump queue to disk in interval
      time.sleep(vglobals.DUMP_INTERVAL)
      indexer.dumpall(vglobals.INDEXQUEUE,vglobals.INDEXLIST)

# exit main thread
dumpall(vglobals.INDEXQUEUE,vglobals.INDEXLIST)
print 'list dumped'

